var retainpaikeCheckedItems;
var data_data;
function getretainpaikeData() {
    
    
    
	var startDate = $("#retainpaikeStartDate").val();
	var endDate = $("#retainpaikeEndDate").val();
    
    
        
    var osID = document.getElementById("retainpaikeOS").options[document.getElementById("retainpaikeOS").selectedIndex].value;
    var typeID = document.getElementById("retainpaikeType").options[document.getElementById("retainpaikeType").selectedIndex].value;
    var datetype = document.getElementById("retainpaikedatetype").options[document.getElementById("retainpaikedatetype").selectedIndex].value;
    
   

	$(".retainpaikeChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("retainpaikeCheckbox");
		retainpaikeCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				retainpaikeCheckedItems.push(items[i].value);
			}
		}

		if(retainpaikeCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/retainpaike?staDate="+startDate+"&pd="+days;
	        
            
            if (osID != ""){
				APIurl += "&os="+osID;
            }
			if (typeID != ""){
				APIurl += "&dt="+typeID;
            }
            
            if (datetype != ""){
				APIurl += "&datetype="+datetype;
            }
            

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "json",
				jsonnp: "callback",
				success:function(data,textStatus){ loadretainpaikeData(data)}
			});
            
            
            $.ajax({
  url: APIurl,
  type: "POST",
  data: "username="+login_username,
success: function(msg){
   //alert('ok');
}
});
            
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var retainpaikeTabArr, retainpaikeDetailArr, retainpaikeSumArr, retainpaikeDateArr, MainSubTitle;
function loadretainpaikeData(data) {
    
    var osID = document.getElementById("retainpaikeOS").options[document.getElementById("retainpaikeOS").selectedIndex].value;
    var typeID = document.getElementById("retainpaikeType").options[document.getElementById("retainpaikeType").selectedIndex].value;
    
    data_data = data;
	var tab = "";
	var startDate = $("#retainpaikeStartDate").val();
	var endDate = $("#retainpaikeEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	retainpaikeTabArr = new Array();
	retainpaikeDetailArr = new Array();
	retainpaikeSumArr = new Array();
	retainpaikeDateArr = new Array();
    
    
    if(data['zongji'] != "0"){

			//显示选择Tab
			
            if(osID==""){

            genTabsretainpaike("retainpaike", "retainpaikeOS", retainpaikeTabArr, retainpaikeDetailArr, retainpaikeSumArr, retainpaikeCheckedItems,0);
        }else if(typeID == ""){

            genTabsretainpaike("retainpaike", "retainpaikeType", retainpaikeTabArr, retainpaikeDetailArr, retainpaikeSumArr, retainpaikeCheckedItems,0);
        }else{ genTabsretainpaike("retainpaike","", retainpaikeTabArr, retainpaikeDetailArr, retainpaikeSumArr, retainpaikeCheckedItems,0);  }
			
            
         
        changeChartType('retainpaike','Table');
        
        
        
        
        //生成表格
        genTop10Tableretainpaike("retainpaikeTable", valueFullNameArr(retainpaikeCheckedItems), retainpaikeTabArr, data['All']['table'], retainpaikeCheckedItems);

        
    }
    else{
        
    alert("选择的时间区间内无数据");
    
    }
	
}

function changeretainpaikeTab(tabName,optionName) {
	
        
    
        //生成表格
        genTop10Tableretainpaike("retainpaikeTable", valueFullNameArr(retainpaikeCheckedItems), retainpaikeTabArr, data_data[tabName]['table'], retainpaikeCheckedItems);
        
    
    
    
	$(".bitem").removeClass("selbitem");
	$("#retainpaikeTab"+tabName).addClass("selbitem");	
    
    
    
	
}



